package com.WaVel.controller.admin;

import com.Emplyment.result.Result;
import com.Emplyment.vo.AdvertisementVo;
import com.WaVel.service.AdvertisementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/advertisement")
public class AdvertisementController {

    @Autowired
    private AdvertisementService advertisementService;

    @GetMapping("/getAdvertisement")
    public Result<List<AdvertisementVo>> getAdvertisement() {
        log.info("获取广告信息");
        List<AdvertisementVo> advertisement = advertisementService.getAdvertisement();
        return Result.success(advertisement);
    }

    @PostMapping("/insertAdvertisement")
    public Result insertAdvertisement(@RequestBody AdvertisementVo advertisementVo) {
        log.info("新增广告信息:{}",advertisementVo);
        advertisementService.insertAdvertisement(advertisementVo);
        return Result.success();
    }

    @PutMapping("/updateAdvertisement")
    public Result updateAdvertisement(@RequestBody AdvertisementVo advertisementVo) {
        log.info("更新广告信息:{}",advertisementVo);
        advertisementService.updateAdvertisement(advertisementVo);
        return Result.success();
    }

    @DeleteMapping("/deleteAdvertisement/{id}")
    public Result deleteAdvertisement(@PathVariable("id") Integer id) {
        log.info("删除广告信息:{}",id);
        advertisementService.deleteAdvertisement(id);
        return Result.success();
    }

}
